﻿using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace Smart.Utils.App
{
    public class MyAssembly
    {
        public static string AssemblyCompany
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (customAttributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)customAttributes[0]).Company;
            }
        }

        public static string AssemblyCopyright
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (customAttributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)customAttributes[0]).Copyright;
            }
        }

        public static string AssemblyDescription
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (customAttributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
            }
        }

        public static string AssemblyProduct
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (customAttributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)customAttributes[0]).Product;
            }
        }

        public static string AssemblyTitle
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (customAttributes.Length > 0)
                {
                    AssemblyTitleAttribute attribute = (AssemblyTitleAttribute)customAttributes[0];
                    if (attribute.Title != "")
                    {
                        return attribute.Title;
                    }
                }
                return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public static string AssemblyTradeMark
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
                if (customAttributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyTrademarkAttribute)customAttributes[0]).Trademark;
            }
        }

        public static string AssemblyVersion
        {
            get
            {
                return Assembly.LoadFile(Application.ExecutablePath).GetName().Version.ToString();
            }
        }
    }
}
